﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Support
{
    /// <summary>
    /// Discription：各种数据（字符串）格式化处理
    /// Author： 
    /// Create Time：2010-07-28
    /// </summary>
    public class FormatHelper
    {
        /// <summary>
        /// 截取会员来源地址信息
        /// </summary>
        /// <param name="p_strLocation">邮政编码$国家名称$所在省份$所在城市$区/县$详细地址</param>
        /// <returns></returns>
        public static string FormatUserLocation(string p_strLocation)
        {
            string result = "";
            if (p_strLocation == null || p_strLocation.Trim() == "" || p_strLocation.Replace('$', ' ').Trim() == "")
            {
                result = "<span>未知地区</span>";
                return result;
            }
            string[] strArrayLocation = p_strLocation.Split('$');
            try
            {
                result = strArrayLocation[1] + strArrayLocation[2] + strArrayLocation[3] + strArrayLocation[4] + strArrayLocation[5] + "（" + strArrayLocation[0] + "）";
            }
            catch
            {
                result = "<span>未知地区</span>";
            }
            return result;
        }
        /// <summary>
        /// 截取会员来源地址信息
        /// </summary>
        /// <param name="p_strLocation">邮政编码$国家名称$所在省份$所在城市$区/县$详细地址</param>
        /// <param name="index">0：邮政编码；1：国家名称；2：所在省份；3：所在城市；4：区/县；5：详细地址</param>
        /// <returns></returns>
        public static string FormatUserLocation(string p_strLocation,int index)
        {
            string result = "";
            if (p_strLocation == null || p_strLocation.Trim() == "" || p_strLocation.Replace('$', ' ').Trim() == "")
            {
                result = "<span>未知地区</span>";
                return result;
            }
            string[] strArrayLocation = p_strLocation.Split('$');
            try
            {
                result = strArrayLocation[index];
            }
            catch
            {
                result = "<span>未知地区</span>";
            }
            return result;
        }
        /// <summary>
        /// 截取会员来源地区
        /// </summary>
        /// <param name="p_strLocation">邮政编码$国家名称$所在省份$所在城市$区/县$详细地址</param>
        /// <returns></returns>
        public static string FormatUserArea(string p_strLocation)
        {
            string result = "";
            if (p_strLocation == null || p_strLocation.Trim() == "" || p_strLocation.Replace('$',' ').Trim() == "")
            {
                result = "<span>未知地区</span>";
                return result;
            }
            string[] strArrayLocation = p_strLocation.Split('$');
            try
            {
                result = strArrayLocation[2] + strArrayLocation[3];
            }
            catch
            {
                result = "<span>未知地区</span>";
            }
            return result;
        }
        /// <summary>
        /// 截取会员来源详细地区
        /// </summary>
        /// <param name="p_strLocation">邮政编码$国家名称$所在省份$所在城市$区/县$详细地址</param>
        /// <returns></returns>
        public static string FormatUserDetailArea(string p_strLocation)
        {
            string result = "";
            if (p_strLocation == null || p_strLocation.Trim() == "" || p_strLocation.Replace('$', ' ').Trim() == "")
            {
                result = "<span>未知地区</span>";
                return result; 
            }
            string[] strArrayLocation = p_strLocation.Split('$');
            try
            {
                result = strArrayLocation[1] + strArrayLocation[2] + strArrayLocation[3] + strArrayLocation[4];
            }
            catch
            {
                result = "<span>未知地区</span>";
            }
            return result; 
        }

        public static string GetBuyerCreditStar(string credit)
        {
            string img = "/content/images/rank/";
            string[] strArrCreditImg = new string[4];
            strArrCreditImg[0] = "b_red_";
            strArrCreditImg[1] = "b_blue_";
            strArrCreditImg[2] = "b_blue_";
            strArrCreditImg[3] = "b_blue_";
            if (credit == null || credit.Trim() == "")
            {
                return img + strArrCreditImg[0] + "1.gif";
            }
            try
            {
                string[] strArrCredit = credit.Split('$');
                int iLevel = strArrCredit[0].ParseToInt(1);
                if (iLevel == 0)
                { 
                    return img + strArrCreditImg[0] + "1.gif";
                }
                int levelType = iLevel / 5;
                int subLevel = iLevel % 5;
                if (levelType > 0 && subLevel == 0)
                {
                    levelType -= 1;
                    subLevel = 5;
                }
                img += strArrCreditImg[levelType] + subLevel.ToString() + ".gif";
            }
            catch
            {
                img += strArrCreditImg[0] + "1.gif";
            }

            return img;
        }
    }
}
